cmake_minimum_required(VERSION 3.5)

project(sdl2_tutorial LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

find_package(SDL2 REQUIRED)
#find_package(SDL2_net REQUIRED)
find_package(SDL2_mixer REQUIRED)
find_package(SDL2_image REQUIRED)
#find_package(SDL2_gfx REQUIRED)
find_package(SDL2_ttf REQUIRED)

list(APPEND tlist main.cpp
    sdl2_02.cpp
    03.cpp
    04_key_presses
    05_optimized_surface_loading_and_soft_stretching
    06_extension_libraries_and_loading_other_image_formats
    07_texture_loading_and_rendering
    09_the_viewport
    10_color_keying
    11_clip_rendering_and_sprite_sheets
    12_color_modulation
    13_alpha_blending
    14_animated_sprites_and_vsync
    15_rotation_and_flipping
    16_true_type_fonts
    17_mouse_events
    18_key_states
    21_sound_effects_and_music
    22_timing
    24_calculating_frame_rate
    25_capping_frame_rate
    26_motion
    27_collision_detection
    28_per-pixel_collision_detection
    29_circular_collision_detection
    30_scrolling
    31_scrolling_backgrounds
    39_tiling
)

foreach(it IN LISTS tlist)
#    list(FIND tlist ${it} n)
#    math(EXPR n "${n}+1")
    if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${it}")
        file(GLOB files "${it}/*.cpp")
#        message("${files}  发地方")
        add_executable("${it}_sdl2" ${files})
        file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/${it}  DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/)
         target_link_libraries("${it}_sdl2" SDL2::Main  SDL2::Mixer SDL2::Image SDL2::TTF #[[ SDL2::Net  SDL2::GFX]])
    else()
#        message(STATUS ${it})
        string(FIND ${it} ".cpp" p)
        string(SUBSTRING ${it} 0 ${p} ss)
        add_executable("${ss}" ${it})
        target_link_libraries("${ss}" SDL2::Main  SDL2::Mixer SDL2::Image SDL2::TTF #[[ SDL2::Net  SDL2::GFX]])
    endif()
endforeach()

#unset(n)
#unset(p)
#unset(ss)

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/hello_world.bmp  DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/02_getting_an_image_on_the_screen/)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/x.bmp  DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/03_event_driven_programming/)
#复制整个04_key_presses目录到${CMAKE_CURRENT_BINARY_DIR}目录下
#file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/04_key_presses  DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/)

#add_executable(sdl2_tutorial main.cpp)
#add_executable(sdl2_tutorial_02 sdl2_02.cpp)

#target_link_libraries(${PROJECT_NAME} SDL2::Main#[[ SDL2::Net SDL2::Mixer SDL2::Image SDL2::TTF SDL2::GFX]])
